QT       -= gui
QT       += core network sql

DEPLOY_DIR = $${OUT_PWD}/../../../deploy
DEPLOY_INCLUDE_DIR = $$DEPLOY_DIR/include
DEPLOY_LIB_DIR = $$DEPLOY_DIR/lib
DEPLOY_BIN_DIR = $$DEPLOY_DIR/bin
DEPLOY_ETC_DIR = $$DEPLOY_DIR/etc
DEPLOY_SHARE_DIR = $$DEPLOY_DIR/share

TEMPLATE = app
CONFIG   += console android_app
TARGET = protoqtrpc_location_service
DESTDIR = $$DEPLOY_BIN_DIR
DEPENDPATH += . src

# Input
HEADERS = \
    src/LocationServiceImpl.h \
    src/LocationDb.h \
    src/Settings.h
SOURCES = src/main.cpp \
    src/LocationServiceImpl.cpp \
    src/LocationDb.cpp \
    src/Settings.cpp

ADDITIONAL_PROTO_PATHS = --proto_path=$$DEPLOY_INCLUDE_DIR
PROTODIR = $${PWD}/../proto
PROTOSUBDIR = protoqtrpc/location
PROTOS = \
        $$PROTODIR/$$PROTOSUBDIR/LocationService.proto

include ($${PWD}/../../../protobuf-compile.pri)

INCLUDEPATH += $$DEPLOY_INCLUDE_DIR
LIBS += -L$$DEPLOY_LIB_DIR -lprotoqtrpc

CONFIGS = \
    etc/location_service.conf

SQLS = \
    db/location_service.sql

sqlite_db.name = sqlite db
sqlite_db.input = SQLS
sqlite_db.output = ${QMAKE_FILE_BASE}.sqlite
sqlite_db.commands = sqlite3 ${QMAKE_FILE_BASE}.sqlite < ${QMAKE_FILE_NAME}
sqlite_db.variable_out =
QMAKE_EXTRA_COMPILERS += sqlite_db

SQLS_NODIR = $$basename(SQLS)
SQLITE_OUTPUT = $$replace(SQLS_NODIR,.sql,.sqlite)
POST_TARGETDEPS += $$SQLITE_OUTPUT

OTHER_FILES += \
    $$SQLS \
    $$CONFIGS

QMAKE_POST_LINK += \
  mkdir -p $$DEPLOY_ETC_DIR; (cd $${PWD} && $${QMAKE_COPY} $$CONFIGS $$DEPLOY_ETC_DIR); \
  mkdir -p $$DEPLOY_SHARE_DIR; $${QMAKE_COPY} $$SQLITE_OUTPUT $$DEPLOY_SHARE_DIR;
